<template>
  <div>
    <h3 class="dialog-plate-title"><span>结果上传</span></h3>
    <el-button type="primary" @click="insertHOtherCheck">新增</el-button>
    <el-table :data="tableList" stripe border class="company-table">
      <el-table-column fixed type="index" label="*" sortable align="center" min-width="40"></el-table-column>
        <el-table-column prop="checkDate" label="检测日期" sortable min-width="100">
          <template slot-scope="scope">
            {{timestampToTime(scope.row.checkDate,'yyyy-mm-dd')}}
          </template>
        </el-table-column>
        <el-table-column prop="uploadDate" label="上传日期" sortable min-width="130">
          <template slot-scope="scope">
            {{timestampToTime(scope.row.uploadDate,'yyyy-mm-dd hh:mm')}}
          </template>
        </el-table-column>
        <el-table-column prop="uploadUserName" label="上传人" sortable min-width="200"></el-table-column>
        <el-table-column fixed="right" label="操作" align="center" min-width="75">
            <template slot-scope="scope">
              <el-button  @click="showDialog(scope.row,'update')" type="text" size="small">详情</el-button>
              <el-button  @click="showDialog(scope.row,'delete')" type="text" size="small">删除</el-button>
            </template>         
        </el-table-column>
    </el-table>
    <el-dialog :title="dialog.title" :visible.sync="dialog.open"  width="90%" top="70px" :close-on-clcick-modal="false" class="bodyNopaddingTop">
      <h3 class="dialog-plate-title mt-1"><span>基本信息</span></h3>
      <el-form :inline="true" :model="dialog.formData" label-width="140px" class="demo-ruleForm">
        <el-form-item label="检测日期" prop="checkDate">
          <el-date-picker type="date" v-model="dialog.formData.checkDate" placeholder="选择日期" class="width220" />
        </el-form-item>
        <el-form-item label="上传人">
          <el-input v-model="dialog.formData.uploadUserName" disabled class="width220"/>
        </el-form-item>
        <el-form-item label="记录日期" prop="uploadDate" >
          <el-date-picker type="date" v-model="dialog.formData.uploadDate" placeholder="选择日期" format="yyyy-MM-dd hh:mm:ss" disabled class="width220"/>
        </el-form-item>
        <el-form-item class="form-item-block text-center">
          <el-button type="primary" @click="submit" >提交</el-button>
        </el-form-item>
      </el-form>
      <h3 class="dialog-plate-title mt-1"><span>附件上传</span></h3>
      <div  v-for="(item,index) in fileList"  :key="index" class="pull-left mr-1">
        <el-image style="width: 148px; height: 148px"  :src="item" fit="fill" :preview-src-list="fileList">{{item}}</el-image>
      </div>
      <el-upload class="avatar-uploader" :action="actionUrl"  ref="refImageUpload" :show-file-list="false" :on-success="handleAvatarSuccess" :before-upload="beforeAvatarUpload"  :on-error="uploadError"> 
        <i  class="el-icon-plus avatar-uploader-icon"></i>
      </el-upload>
      
   </el-dialog>
   <!-- 图片查看 -->
  </div>
</template>
<script>
import {externalHospitalReportList,insertExternalHospitalReport,externalHospitalReportUpload,externalHospitalReportUploadList,updateCtEHR,updateCsEHR,updateOtherEHR,deleteOtherOthercheck} from "plugins/axios/inquiryRecord.js"
export default {
  props:{
    idNo:{
      type:[String,Number]
    },
    type:{
      type:[String,Number]
    }
  },
  data(){
    return {
      dialog:{
        title:'',
        open:false,
        formData:{}
      },
      tableList:[],
      actionUrl:'',
      fileList:[],
      typeName:''
    }
  },
  created(){
  },
  mounted(){},
  watch:{},
  computed:{},
  methods:{
    init(){
      switch(this.type){
        case '2':
          this.typeName="CT"
          break;
        case '3':
          this.typeName="超声"
         break;
        case '4':
          this.typeName="其他"
         break;
      }
     this.getList();
    },
    //点击新增按钮
    insertHOtherCheck(type){
      let self = this;
      insertExternalHospitalReport(self.idNo,self.type).then(res=>{
        self.getList(content=>{
          self.dialog.title=`新增外院报告-${this.typeName}`;
          self.dialog.open=true;
          self.dialog.formData={...content}
          self.actionUrl=externalHospitalReportUpload(content.id,self.type)
          self.externalHospitalReportUploadList()
        })
      })
    },
    /**获取列表*/ 
    getList(cb){
      let self = this;
      externalHospitalReportList(self.idNo,self.type).then(res=>{
        self.tableList= res.content;
        cb&&cb(res.content&&res.content.length>0?res.content[0]:{})
         
      })
    },
    /**获取附件上传列表*/ 
    externalHospitalReportUploadList(){
       let self = this;
      externalHospitalReportUploadList(self.type,self.dialog.formData.id).then(res=>{
        self.fileList=res.content[0].images;
      })
    },
    /**点击详情按钮*/ 
    showDialog(row,type){
      let self=this;
       if(type==='update'){

          self.dialog.title=`修改外院报告-${this.typeName}`;
          self.dialog.open=true;
          self.dialog.formData={...row}
          self.actionUrl=externalHospitalReportUpload(row.id,this.type)
          self.externalHospitalReportUploadList()
       }
       if(type==='delete'){
          self.$confirm('是否删除?', '提示', {
            confirmButtonText: '删除',
            cancelButtonText: '取消',
            confirmButtonClass:'bg-warning noBorder',
            type: 'warning'
          }).then(() => {
            deleteOtherOthercheck(row.id).then(res=>{
                    self.$message.success('删除成功!');
                    self.getList();
                })
            }).catch(()=> {});
       }

    },
    submit(){
      let self=this,
      postData={...self.dialog.formData};
      switch(self.type){
        case '2':
          updateCtEHR(postData).then(res=>{
            self.dialog.open = false;
            self.$message.success(`${this.dialog.title}成功`);
            self.init();
          })
          break;
        case '3':
          updateCsEHR(postData).then(res=>{
            self.dialog.open = false;
            self.$message.success(`${this.dialog.title}成功`);
            self.init();
          })
          break;
        case '4':
          updateOtherEHR(postData).then(res=>{
            self.dialog.open = false;
            self.$message.success(`${this.dialog.title}成功`);
            self.init();
          })
          break;
      }
      
    },
    //图片上传成功
    handleAvatarSuccess(response, file, fileList){
      this.$refs.refImageUpload.clearFiles()
      this.externalHospitalReportUploadList()
    },
    beforeAvatarUpload(){},
    //上传视频失败
    uploadError(err,file, fileList){
       this.$message.error(err)
    },
  }
}
</script>
<style scoped>

</style>